home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / rodent.zip / MOUSE.PAS < prev    next >
Pascal/Delphi Source File  |  1987-10-19  |  7KB  |  228 lines

  1. Unit mouse;
  2.  
  3. {------------------------------------------------------------}
  4. { For Turbo Pascal Release 4.n. Won't work with older levels }
  5. { Implements calls to mouse device driver. Works with the    }
  6. { Logitech and Microsoft mice, and anything else compatible. }
  7. {                                                            }
  8. {                           NOTE!!!                          }
  9. {      COMPILER OPTIONS MUST BE SET TO FORCE FAR CALLS!      }
  10. {      If not, user defined task installed by mInstTask      }
  11. {                   will crash the system.                   }
  12. {------------------------------------------------------------}
  13.  
  14. Interface
  15.  
  16. {$U \tp}
  17. Uses DOS;                     { For interrupts and registers }
  18.  
  19. Const
  20.   MDD = $33;             { Interrupt for mouse device driver }
  21.  
  22. Type
  23.   resetRec = record        { Initialized by mouse function 0 }
  24.     exists   : Boolean;           { TRUE if mouse is present }
  25.     nButtons : integer;                 { # buttons on mouse }
  26.   End;
  27.  
  28.   locRec = record    { Initialized by mouse fcns 3, 5, and 6 }
  29.     buttonStatus,    { bits 0-2 on if corresp button is down }
  30.     opCount,               { # times button has been clicked }
  31.                              { opCount not returned by fcn 3 }
  32.     column,                                       { position }
  33.     row      : integer;
  34.   End;
  35.  
  36.   moveRec = record             { Initialized by mouse fcn 11 }
  37.     hCount,                        { net horizontal movement }
  38.     vCount : integer;                { net vertical movement }
  39.   End;
  40.  
  41. Var  Reg : Registers;
  42.  
  43. { These are the Microsoft mouse functions }
  44. Procedure mReset (var mouse : resetRec);       { function  0 }
  45. Procedure mShow;                               { function  1 }
  46. Procedure mHide;                               { function  2 }
  47. Procedure mPos (var mouse : locRec);           { function  3 }
  48. Procedure mMoveto (col, row : integer);        { function  4 }
  49. Procedure mPressed (button : integer;
  50.                     var mouse : locRec);       { function  5 }
  51. Procedure mReleased (button : integer;
  52.                     var mouse : locRec);       { function  6 }
  53. Procedure mColRange (min, max : integer);      { function  7 }
  54. Procedure mRowRange (min, max : integer);      { function  8 }
  55. Procedure mGraphCursor (hHot, vHot : integer;
  56.                    maskSeg, maskOfs : word);   { function  9 }
  57. Procedure mTextCursor (ctype, p1, p2 : word);  { function 10 }
  58. Procedure mMotion (var moved : moveRec);       { function 11 }
  59. Procedure mInstTask (mask,
  60.                      taskSeg, taskOfs : word); { function 12 }
  61. Procedure mLpenOn;                             { function 13 }
  62. Procedure mLpenOff;                            { function 14 }
  63. Procedure mRatio (horiz, vert : integer);      { function 15 }
  64. { ---------------------------------------------------------- }
  65.  
  66. IMPLEMENTATION
  67.  
  68. Function lower (n1, n2 : integer) : integer;  { Local to unit}
  69. Begin
  70.   If n1 < n2 then lower := n1
  71.   Else lower := n2;
  72. End;
  73.  
  74. Function upper (n1, n2 : integer) : integer; { Local to unit }
  75. Begin
  76.   If n1 > n2 then upper := n1
  77.   Else upper := n2;
  78. End;
  79. { --------------------------- }
  80. Procedure mReset;        { Resets mouse to default condition }
  81. Begin
  82.   reg.ax := 0;
  83.   intr (MDD, reg);
  84.   if reg.ax <> 0 then
  85.     mouse.exists := TRUE
  86.   else
  87.     mouse.exists := FALSE;
  88.   mouse.nButtons := reg.bx;
  89. End;
  90. { --------------------------- }
  91. Procedure mShow;                 { Make mouse cursor visible }
  92. Begin
  93.   reg.ax := 1;
  94.   intr (MDD, reg);
  95. End;
  96. { --------------------------- }
  97. Procedure mHide;               { Make mouse cursor invisible }
  98. Begin
  99.   reg.ax := 2;
  100.   intr (MDD, reg);
  101. End;
  102. { --------------------------- }
  103. Procedure mPos;              { Get mouse status and position }
  104. Begin
  105.   reg.ax := 3;
  106.   intr (MDD, reg);
  107.   mouse.buttonStatus := reg.bx;
  108.   mouse.column := reg.cx;
  109.   mouse.row := reg.dx;
  110. End;
  111. { --------------------------- }
  112. Procedure mMoveto;       { Move mouse cursor to new location }
  113. Begin
  114.   reg.ax := 4;
  115.   reg.cx := col;
  116.   reg.dx := row;
  117.   intr (MDD, reg);
  118. End;
  119. { --------------------------- }
  120. Procedure mPressed;  { Get pressed info about a given button }
  121. Begin
  122.   reg.ax := 5;
  123.   reg.bx := button;
  124.   intr (MDD, reg);
  125.   mouse.buttonStatus := reg.ax;
  126.   mouse.opCount := reg.bx;
  127.   mouse.column := reg.cx;
  128.   mouse.row := reg.dx;
  129. End;
  130. { --------------------------- }
  131. Procedure mReleased;      { Get released into about a button }
  132. Begin
  133.   reg.ax := 6;
  134.   reg.bx := button;
  135.   intr (MDD, reg);
  136.   mouse.buttonStatus := reg.ax;
  137.   mouse.opCount := reg.bx;
  138.   mouse.column := reg.cx;
  139.   mouse.row := reg.dx;
  140. End;
  141. { --------------------------- }
  142. Procedure mColRange;            { Set column range for mouse }
  143. Begin
  144.   reg.ax := 7;
  145.   reg.cx := lower (min, max);
  146.   reg.dx := upper (min, max);
  147.   intr (MDD, reg);
  148. End;
  149. { --------------------------- }
  150. Procedure mRowRange;               { Set row range for mouse }
  151. Begin
  152.   reg.ax := 8;
  153.   reg.cx := lower (min, max);
  154.   reg.dx := upper (min, max);
  155.   intr (MDD, reg);
  156. End;
  157. { --------------------------- }
  158. Procedure mGraphCursor;          { Set mouse graphics cursor }
  159. Begin
  160.   reg.ax := 9;
  161.   reg.bx := hHot;
  162.   reg.cx := vHot;
  163.   reg.dx := maskOfs;
  164.   reg.es := maskSeg;
  165.   intr (MDD, reg);
  166. End;
  167. { --------------------------- }
  168. Procedure mTextCursor;               { Set mouse text cursor }
  169.  
  170.    { NOTES:                                            }
  171.    { Type 0 is the software cursor. When specified, p1 }
  172.    {   and p2 are the screen and cursor masks.         }
  173.    { Type 1 is the hardware cursor. When specified, p1 }
  174.    {   and p2 are the start and stop scan lines, i.e.  }
  175.    {   the cursor shape.                               }
  176.  
  177. Begin
  178.   reg.ax := 10;
  179.   reg.bx := ctype;
  180.   reg.cx := p1;
  181.   reg.dx := p2;
  182.   intr (MDD, reg);
  183. End;
  184. { --------------------------- }
  185. Procedure mMotion;   { Net movement of mouse since last call }
  186.                              { Expressed in mickeys (1/100") }
  187. Begin
  188.   reg.ax := 11;
  189.   intr (MDD, reg);
  190.   moved.hCount := reg.cx;
  191.   moved.vCount := reg.dx;
  192. End;
  193. { --------------------------- }
  194. Procedure mInstTask;             { Install user-defined task }
  195. Begin
  196.   reg.ax := 12;
  197.   reg.cx := mask;
  198.   reg.dx := taskOfs;
  199.   reg.es := taskSeg;
  200.   intr (MDD, reg);
  201. End;
  202. { --------------------------- }
  203. Procedure mLpenOn;   { Turn on light pen emulation (default) }
  204. Begin
  205.   reg.ax := 14;
  206.   intr (MDD, reg);
  207. End;
  208. { --------------------------- }
  209. Procedure mLpenOff;           { Turn off light pen emulation }
  210. Begin
  211.   reg.ax := 15;
  212.   intr (MDD, reg);
  213. End;
  214. { --------------------------- }
  215. Procedure mRatio;                { Set mickey to pixel ratio }
  216.  
  217.    { NOTES:                                       }
  218.    { Ratios are R/8.                              }
  219.    { Default is 16 for vertical, 8 for horizontal }
  220.  
  221. Begin
  222.   reg.ax := 15;
  223.   reg.cx := horiz;
  224.   reg.dx := vert;
  225. End;
  226. { --------------------------- }
  227.  
  228. End.